﻿

#region
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Data.OleDb;
using System.Data;
using DTO;
#endregion

namespace DAO
{
    public class PhieuThuePhongDAO:Dataprovider
    {
        #region Phuong thuc
        public PhieuThuePhongDAO()
        {
        }

        // lay danh sach phieu thue phong.
        public ArrayList getDsPhieuThuePhong()
        {
            connect();
            string query = "SELECT * FROM PHIEUTHUEPHONG";
            adapter = new OleDbDataAdapter(query, connection);
            DataSet dataset = new DataSet();
            adapter.Fill(dataset);
            ArrayList arr = ConvertDataSetToArrayList(dataset);

            return arr;
        }

        // lay du lieu dua vao dataRow
        protected override object GetDataFromDataRow(DataTable dt, int i)
        {
            PhieuThuePhongDTO ptp = new PhieuThuePhongDTO();

            ptp.MaPhieuThue = dt.Rows[i]["MaPhieuThue"].ToString();
            ptp.MaKhachHang = dt.Rows[i]["MaKhachHang"].ToString();
            ptp.MaPhong = dt.Rows[i]["MaPhong"].ToString();
            ptp.NgayTra = DateTime.Parse(dt.Rows[i]["NgayTra"].ToString());
            ptp.NgayThue = DateTime.Parse(dt.Rows[i]["NgayThue"].ToString());
            
            return (object)ptp;
        }

        public void insert(PhieuThuePhongDTO info)
        {
            string insertCommand = "INSERT INTO PHIEUTHUEPHONG VALUES('" +
                info.MaPhieuThue + "', '" +
                info.MaKhachHang + "', '" +
                info.MaPhong + "', '" +
                info.NgayTra + "', '" +
                info.NgayThue + ")";

            executeNonQuery(insertCommand);
        }

        public void update(PhieuThuePhongDTO info)
        {
            string updateCommand = "UPDATE PHIEUTHUEPHONG " +
                                    "SET MaKhachHang = '" + info.MaKhachHang + "', " +
                                    " MaPhong = '" + info.MaPhong + "', " +
                                    " NgayTra = '" + info.NgayTra + "', " +
                                    " NgayThue = '" + info.NgayThue + "', " +
                                    " WHERE MaPhieuThue = '" + info.MaPhieuThue + "'";


            executeNonQuery(updateCommand);
        }

        public void delete(string maPT)
        {
            string deleteCommand = "DELETE FROM PHIEUTHUEPHONG WHERE MaPhieuThue = '" + maPT + "'";
            executeNonQuery(deleteCommand);
        }
        #endregion
    }
}
